package com.boot2.core.service;

import com.boot2.core.dao.i.SysDictDataDao;
import com.boot2.core.model.SysDictData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * 
 * @ClassName: SysDictDataService
 * @Description: 【字典数据】 Service
 * @author zhangweilin
 * @date 2020-6-17 12:18:17
 *
 */
@Service
public class SysDictDataService {

	@Autowired
	SysDictDataDao sysDictDataDao;

	/**
	 * 根据字典类型，得到kv对
	 * @param type
	 * @return
	 */
	public Map<String, String> getKv(String type) {
		List<SysDictData> sysDictDataList = sysDictDataDao.findByDictTypeAndStatusOrderByDictSort(type, false);
		Map<String, String> map = sysDictDataList.stream().collect(Collectors.toMap(e -> e.getDictValue(), e -> e.getDictLabel()));
		return map;
	}


	/**
	 * 根据字典类型，得到kv对
	 * @param type
	 * @return
	 */
	public Map<String, SysDictData> getKvs(String type) {
		List<SysDictData> sysDictDataList = sysDictDataDao.findByDictTypeAndStatusOrderByDictSort(type, false);
		Map<String, SysDictData> map = sysDictDataList.stream().collect(Collectors.toMap(e -> e.getDictValue(), e -> e));
		return map;
	}



}
